package com.lcy.redismessage.controller;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.UUID;
import com.lcy.redismessage.domain.vo.RedisQueueMsg;
import com.lcy.redismessage.service.MessageService;
import com.lcy.redismessage.service.RedissonService;
import org.redisson.api.RBoundedBlockingQueue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.concurrent.TimeUnit;

/**
 * @author player six
 * @email jslcylcy@163.com
 * @create 2018-05-22 17:17
 **/
@RestController
public class TestController {

    @Autowired
    private MessageService messageService;
    @Autowired
    private RedissonService redissonService;


    @GetMapping("/add-topic/{msg}")
    public String addTopic(@PathVariable("msg") String message) {
        messageService.sendTopicMessage(message);
        return "success";
    }

    @GetMapping("/add-queue")
    public String addQueue(String message) {
        messageService.sendQueueMessage(message);
        return "success";
    }

    @GetMapping("/redisson-queue/{msg}")
    public String redissonQueue(@PathVariable("msg")String message) {

        RBoundedBlockingQueue<RedisQueueMsg> blockingQueue = redissonService.getBoundedBlockingQueue();

        String ss = message;
        System.out.println("redisson-queue 接收参数:"+ message);
        blockingQueue.offer(new RedisQueueMsg(UUID.randomUUID().toString(),ss + DateUtil.now()));
        return "success";
    }

    @GetMapping("/get-redisson-queue/{msg}")
    public String getRedissonQueue(@PathVariable("msg")String message) {
        System.out.println("getRedissonQueue  获取参数:"+ message);
       // redissonService.getQueueVal();
        return "success";
    }
}
